<div id="manage-chapters">

  <h4><%=h "Delete/reorder chapters".t %></h4>

  <p><%=h "Drag chapters to change their order.".t %><p>

  <% form_tag url_for(:action => 'update_positions') do %>
  <ul id="sortable_chapter_list">
    <% for chapter in @chapters %>
      <li id="chapter_<%= chapter.id %>" class='chapter-position-list'>
        <%= text_field_tag 'chapters[]', nil, :size => 3, :maxlength => 3, :class => 'chapter-position-field' -%>
        <span id='position-for-<%= chapter.id %>'><%= chapter.position %></span>. 
        <% if chapter.title %>
          <%=h chapter.title %>    
        <% else %>
          <%=h "Chapter".t %> <%=h chapter.position %>    
        <% end %>
        <ul class='chapter-control navigation'>
          <li><%= link_to 'edit'.t, [:edit, @work, chapter] -%></li>
           <%- if @work.chapters.count > 1 -%>
             <li><%= link_to 'delete'.t, [@work, chapter], :confirm => 'Are you sure?'.t, :method => :delete %></li>
             <% if @work.pseuds.size > 1 && chapter.pseuds.size > 1 -%>
               <li><%= link_to "Remove me as author".t, {:action => "edit", :id => chapter.id, :remove => "me"}, :confirm => 'You will no longer be able to edit this chapter. Are you sure?'.t %></li>
             <% end -%> 
          <%- end -%> )
      	</ul>
      </li>
    <% end %>    
  </ul>
  <p class="submit"><%= submit_tag "Update Positions".t %></p>
  <% end %>
</div>

<%= sortable_element('sortable_chapter_list', :url => {:action => :update_positions}) %>
